package com.hqq.exercise.string;

import java.util.Scanner;

/**
 * BracketMatch 括号匹配问题
 * Created by heqianqian on 2017/9/10.
 */
public class BracketMatch {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        int depth = depth(str);
        System.out.println(depth);
    }

    /**
     * 计算括号的深度
     */
    public static int depth(String str){
        int ans = 0,cnt = 0;
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i)=='('){
                cnt++;
                ans = Math.max(ans,cnt);
            }else if (str.charAt(i)==')'){
                cnt--;
            }
        }
        return ans;
    }
}
